home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / amiga_segs.s < prev    next >
Text File  |  1998-03-01  |  20KB  |  797 lines

  1.         mc68020
  2.  
  3.         xdef    _R_RenderSegLoop
  4.         xdef    @R_RenderSegLoop
  5.  
  6.         xdef    _R_PointToDist
  7.         xdef    @R_PointToDist
  8.  
  9.         xdef    @R_RenderMaskedSegRange
  10.         xdef    _R_RenderMaskedSegRange
  11.  
  12.         xdef    @R_ScaleFromGlobalAngle
  13.         xdef    _R_ScaleFromGlobalAngle
  14.  
  15.         include    "exec/types.i"
  16.  
  17.         section    text,code
  18.  
  19.         near    a4,-2
  20.  
  21. ;-----------------------------------------------------------------------
  22.         xref    _segtextured        ; boolean
  23.         xref    _markfloor        ; boolean
  24.         xref    _markceiling        ; boolean
  25.         xref    _maskedtexture        ; boolean
  26.         xref    _maskedtexturecol    ; short *
  27.         xref    _toptexture        ; short
  28.         xref    _bottomtexture        ; short
  29.         xref    _midtexture        ; short
  30.         xref    _rw_x            ; int
  31.         xref    _rw_stopx        ; int
  32.         xref    _rw_centerangle        ; angle_t
  33.         xref    _rw_offset        ; fixed_t
  34.         xref    _rw_distance        ; fixed_t
  35.         xref    _rw_scale        ; fixed_t
  36.         xref    _rw_scalestep        ; fixed_t
  37.         xref    _rw_midtexturemid    ; fixed_t
  38.         xref    _rw_toptexturemid    ; fixed_t
  39.         xref    _rw_bottomtexturemid    ; fixed_t
  40.         xref    _pixhigh        ; fixed_t
  41.         xref    _pixlow            ; fixed_t
  42.         xref    _pixhighstep        ; fixed_t
  43.         xref    _pixlowstep        ; fixed_t
  44.         xref    _topfrac        ; fixed_t
  45.         xref    _topstep        ; fixed_t
  46.         xref    _bottomfrac        ; fixed_t
  47.         xref    _bottomstep        ; fixed_t
  48.         xref    _walllights        ; lighttable_t **
  49.         xref    _ceilingclip        ; short *
  50.         xref    _ceilingplane        ; visplane_t *
  51.         xref    _floorclip        ; short *
  52.         xref    _floorplane        ; visplane_t *
  53.         xref    _xtoviewangle        ; angle_t *
  54.         xref    _finetangent        ; fixed_t[]
  55.         xref    _FixedMul
  56.         xref    _colfunc
  57.         xref    _dc_x
  58.         xref    _dc_iscale
  59.         xref    _dc_yl
  60.         xref    _dc_yh
  61.         xref    _dc_colormap
  62.         xref    _dc_texturemid
  63.         xref    _dc_source
  64.         xref    _viewheight
  65.  
  66.         xref    @R_GetColumn
  67.  
  68.         cnop    0,4
  69.  
  70. _R_RenderSegLoop
  71. @R_RenderSegLoop
  72.         movem.l    d2-d7/a2/a3/a5/a6,-(sp)
  73.         movea.l    _rw_x(a4),a2    ; a2 = rw_x
  74.         movea.l    _topfrac(a4),a3    ; a3 = topfrac
  75.         movea.l    _bottomfrac(a4),a5 ; a5 = bottomfrac
  76.         movea.l    _rw_scale(a4),a6 ; a6 = rw_scale
  77.         bra.w    1$        ; for ( ; rw_x < rw_stopx ; rw_x++)
  78.  
  79. 20$        move.l    a2,d0        ; d0 = rw_x
  80.         move.l    a3,d7        ; d7 = topfrac
  81. ;;;        lea    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  82.         movea.l    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  83.         subq.l    #1,d7        ; d7 = topfrac - 1
  84.         move.w    (a0,d0.l*2),d3    ; d3.w = ceilingclip[rw_x]
  85.         asr.l    #8,d7        ; d7 = (topfrac - 1) >> 8
  86.         ext.l    d3        ; d3 = ceilingclip[rw_x]
  87.         asr.l    #4,d7        ; d7 = (topfrac - 1) >> 12
  88.         addq.l    #1,d3        ; d3 = top = ceilingclip[rw_x] + 1
  89.         addq.l    #1,d7        ; d7 = yl = (topfrac + (1 << 12) - 1) >> 12
  90.         cmp.l    d3,d7
  91.         bge.b    2$
  92.         move.l    d3,d7        ; d7 = yl = ceilingclip[rw_x] + 1
  93.  
  94. 2$        tst.l    _markceiling(a4) ; if (markceiling) {
  95.         beq.b    3$
  96. ;;;        lea    _floorclip(a4),a1 ; a1 -> floorclip
  97.         movea.l    _floorclip(a4),a1 ; a1 -> floorclip
  98.         move.l    d7,d4        ; d4 = yl
  99.         move.w    (a1,d0.l*2),d1    ; d1.w = floorclip[rw_x]
  100.         subq.l    #1,d4        ; d4 = bottom = yl - 1
  101.         ext.l    d1        ; d1 = floorclip[rw_x]
  102.         cmp.l    d1,d4        ; if (bottom >= floorclip[rw_x])
  103.         blt.b    4$
  104.         move.l    d1,d4
  105.         subq.l    #1,d4        ; d4 = bottom = floorclip[rw_x] - 1
  106.  
  107. 4$        cmp.l    d4,d3        ; if (top <= bottom)
  108.         bgt.b    3$
  109.  
  110. ;;;        movea.l    _ceilingplane(a4),a1
  111. ;;;        adda.l    d0,a1        ; a1 -> ceilingplane->0[rw_x]
  112. ;;;        move.b    d3,$15(a1)    ; ceilingplane->top[rw_x] = top
  113. ;;;        move.b    d4,$157(a1)    ; ceilingplane->bottom[rw_x] = bottom
  114.  
  115.         movea.l    _ceilingplane(a4),a0
  116.         movea.l    20(a0),a1
  117.         move.w    d3,(a1,d0.l*2)    ; ceilingplane->top[rw_x] = top
  118.         movea.l    24(a0),a1
  119.         move.w    d4,(a1,d0.l*2)    ; ceilingplane->bottom[rw_x] = bottom
  120.  
  121. 3$        move.l    a5,d3        ; d3 = bottomfrac
  122. ;;;        lea    _floorclip(a4),a1    ; a1 -> floorclip
  123.         movea.l    _floorclip(a4),a1    ; a1 -> floorclip
  124.         asr.l    #8,d3        ; d3 = bottomfrac >> 8
  125.         move.w    (a1,d0.l*2),d1    ; d1.w = floorclip[rw_x]
  126.         asr.l    #4,d3        ; d3 = yh = bottomfrac >> 12
  127.         ext.l    d1        ; d1 = floorclip[rw_x]
  128.         cmp.l    d1,d3        ; if (yh >= floorclip[rw_x])
  129.         blt.b    5$
  130.         move.l    d1,d3
  131.         subq.l    #1,d3        ; d3 = yh = floorclip[rw_x] - 1
  132.  
  133. 5$        tst.l    _markfloor(a4)    ; if (markfloor)
  134.         beq.b    6$
  135.         move.l    d3,d4        ; d4 = yh
  136. ;;;        lea    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  137.         movea.l    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  138.         move.w    (a0,d0.l*2),d2    ; d2.w = ceilingclip[rw_x]
  139.         addq.l    #1,d4        ; d4 = top = yh + 1
  140.         ext.l    d2        ; d2 = ceilingclip[rw_x]
  141.         subq.l    #1,d1        ; d1 = bottom = floorclip[rw_x] - 1
  142.         cmp.l    d2,d4        ; if (top <= ceilingclip[rw_x])
  143.         bgt.b    7$
  144.         move.l    d2,d4
  145.         addq.l    #1,d4        ; d4 = top = ceilingclip[rw_x] + 1
  146. 7$        cmp.l    d1,d4        ; if (top <= bottom)
  147.         bgt.b    6$
  148.  
  149. ;;;        movea.l    _floorplane(a4),a1
  150. ;;;        adda.l    d0,a1        ; a1 -> floorplane->0[rw_x]
  151. ;;;        move.b    d4,$15(a1)    ; floorplane->top[rw_x] = top
  152. ;;;        move.b    d1,$157(a1)    ; floorplane->bottom[rw_x] = bottom
  153.  
  154.         movea.l    _floorplane(a4),a0
  155.         movea.l    20(a0),a1
  156.         move.w    d4,(a1,d0.l*2)    ; ceilingplane->top[rw_x] = top
  157.         movea.l    24(a0),a1
  158.         move.w    d1,(a1,d0.l*2)    ; ceilingplane->bottom[rw_x] = bottom
  159.  
  160. 6$        tst.l    _segtextured(a4) ; if (segtextured)
  161.         beq.b    8$
  162. ;;;        lea    _xtoviewangle(a4),a0 ; a0 -> xtoviewangle
  163.         movea.l    _xtoviewangle(a4),a0 ; a0 -> xtoviewangle
  164.         move.l    _rw_centerangle(a4),d1
  165.         add.l    (a0,d0.l*4),d1    ; d1 = rw_centerangle + xtoviewangle[rw_x]
  166.         swap    d1        ; d1 = angle
  167.         lea    (_finetangent),a0 ; a0 -> finetangent
  168.         lsr.w    #3,d1
  169.         move.l    (a0,d1.w*4),d0    ; d0 = finetangent[angle]
  170.         movea.l    _FixedMul(a4),a0
  171.         move.l    _rw_distance(a4),d1
  172.         jsr    (a0)        ; d0 = FixedMul(finetangent[angle],rw_distance)
  173.         move.l    _rw_offset(a4),d5
  174.         move.l    a6,d4        ; d4 = rw_scale
  175.         sub.l    d0,d5        ; d5 = rw_offset-FixedMul(finetangent[angle],rw_distance)
  176.         asr.l    #8,d4
  177.         swap    d5        ; d5.w = texturecolumn >>= 16
  178.         asr.l    #4,d4        ; d4 = index = rw_scale >> 12
  179.         ext.l    d5        ; d5 = texturecolumn
  180.         moveq    #$30,d2        ; d2 = MAXLIGHTSCALE = $30
  181.         cmp.l    d2,d4        ; if (index >= MAXLIGHTSCALE)
  182.         bcs.b    9$
  183.         moveq    #$2f,d4        ; d4 = index = MAXLIGHTSCALE - 1
  184. 9$        movea.l    _walllights(a4),a0
  185.         moveq    #-1,d0        ; d0 = $ffffffff
  186.         move.l    (a0,d4.l*4),_dc_colormap(a4) ; dc_colormap = walllights[index]
  187.         move.l    a2,_dc_x(a4)    ; dc_x = rw_x
  188.         move.l    a6,d1        ; d1 = rw_scale
  189.         divu.l    d1,d0
  190.         move.l    d0,_dc_iscale(a4) ; dc_iscale = $ffffffff / rw_scale
  191.  
  192. 8$        move.l    _midtexture(a4),d0 ; if (midtexture)
  193.         beq.b    10$
  194.         move.l    d7,_dc_yl(a4)    ; dc_yl = yl
  195.         move.l    d3,_dc_yh(a4)    ; dc_yh = yh
  196.         move.l    _rw_midtexturemid(a4),_dc_texturemid(a4)
  197.         move.l    d5,d1        ; d1 = texturecolumn
  198.         jsr    (@R_GetColumn)
  199.         move.l    d0,_dc_source(a4) ; dc_source = R_GetColumn(midtexture,texturecolumn)
  200.         movea.l    _colfunc(a4),a0
  201.         jsr    (a0)        ; colfunc()
  202.         move.l    a2,d0        ; d0 = rw_x
  203.         move.l    _viewheight(a4),d1 ; d1 = viewheight
  204. ;;;        lea    _ceilingclip(a4),a0
  205.         movea.l    _ceilingclip(a4),a0
  206.         move.w    d1,(a0,d0.l*2)    ; ceilingclip[rw_x] = viewheight
  207. ;;;        lea    _floorclip(a4),a0
  208.         movea.l    _floorclip(a4),a0
  209.         move.w    #$ffff,(a0,d0.l*2) ; floorclip[rw_x] = -1
  210.         bra.w    11$
  211.  
  212. 10$        move.l    _toptexture(a4),d0 ; if (toptexture)
  213.         beq.b    12$
  214.         move.l    _pixhighstep(a4),d1 ; d1 = pixhighstep
  215.         move.l    _pixhigh(a4),d2    ; d2 = pixhigh
  216.         add.l    d1,_pixhigh(a4)    ; pixhigh += pixhighstep
  217. ;;;        lea    _floorclip(a4),a0 ; a0 -> floorclip
  218.         movea.l    _floorclip(a4),a0 ; a0 -> floorclip
  219.         asr.l    #8,d2        ; d2 = pixhigh >> 8
  220.         move.l    a2,d1        ; d1 = rw_x
  221.         move.w    (a0,d1.l*2),d1    ; d1.w = floorclip[rw_x]
  222.         asr.l    #4,d2        ; d2 = pixhigh >> 12
  223.         ext.l    d1        ; d1 = floorclip[rw_x]
  224.         move.l    d2,d6        ; d6 = mid = pixhigh >> 12
  225.         cmp.l    d1,d6        ; if (mid >= floorclip[rw_x])
  226.         blt.b    13$
  227.         move.l    d1,d6
  228.         subq.l    #1,d6        ; d6 = mid = floorclip[rw_x] - 1
  229. 13$        cmp.l    d7,d6        ; if (mid >= yl)
  230.         blt.b    14$
  231.         move.l    d7,_dc_yl(a4)    ; dc_yl = yl
  232.         move.l    d6,_dc_yh(a4)    ; dc_yh = mid
  233.         move.l    _rw_toptexturemid(a4),_dc_texturemid(a4)
  234.         move.l    d5,d1        ; d1 = texturecolumn, d0 = toptexture
  235.         jsr    (@R_GetColumn)
  236.         move.l    d0,_dc_source(a4)    ; dc_source = R_GetColumn(d0,d1)
  237.         movea.l    _colfunc(a4),a0
  238.         jsr    (a0)        ; colfunc()
  239.         move.l    a2,d0        ; d0 = rw_x
  240. ;;;        lea    _ceilingclip(a4),a0
  241.         movea.l    _ceilingclip(a4),a0
  242.         move.w    d6,(a0,d0.l*2)    ; ceilingclip[rw_x] = mid
  243.         bra.b    15$
  244.  
  245. 12$        tst.l    _markceiling(a4) ; else if (markceiling)
  246.         beq.b    15$
  247. 14$        subq.l    #1,d7        ; d7 = yl - 1
  248.         move.l    a2,d0        ; d0 = rw_x
  249. ;;;        lea    _ceilingclip(a4),a0
  250.         movea.l    _ceilingclip(a4),a0
  251.         move.w    d7,(a0,d0.l*2)    ; ceilingclip[rw_x] = yl - 1
  252.  
  253. 15$        move.l    _bottomtexture(a4),d0 ; if (bottomtexture)
  254.         beq.b    16$
  255.         move.l    _pixlow(a4),d6    ; d6 = pixlow
  256.         move.l    d6,d1        ; d1 = pixlow
  257. ;;;        lea    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  258.         movea.l    _ceilingclip(a4),a0 ; a0 -> ceilingclip
  259.         add.l    _pixlowstep(a4),d1 ; d1 = pixlow + pixlowstep
  260.         subq.l    #1,d6        ; d6 = pixlow - 1
  261.         move.l    d1,_pixlow(a4)    ; pixlow += pixlowstep
  262.         asr.l    #8,d6        ; d6 = (pixlow - 1) >> 8
  263.         move.l    a2,d1        ; d1 = rw_x
  264.         asr.l    #4,d6        ; d6 = (pixlow - 1) >> 12
  265.         move.w    (a0,d1.l*2),d1    ; d1.w = ceilingclip[rw_x]
  266.         addq.l    #1,d6        ; d6 = mid = (pixlow + (1 << 12) - 1) >> 12
  267.         ext.l    d1        ; d1 = ceilingclip[rw_x]
  268.         cmp.l    d1,d6        ; if (mid <= ceilingclip[rw_x])
  269.         bgt.b    17$
  270.         move.l    d1,d6
  271.         addq.l    #1,d6        ; d6 = mid = ceilingclip[rw_x] + 1
  272. 17$        cmp.l    d3,d6        ; if (mid <= yh)
  273.         bgt.b    18$
  274.         move.l    d6,_dc_yl(a4)    ; dc_yl = mid
  275.         move.l    d3,_dc_yh(a4)    ; dc_yh = yh
  276.         move.l    _rw_bottomtexturemid(a4),_dc_texturemid(a4)
  277.         move.l    d5,d1        ; d1 = texturecolumn, d0 = bottomtexture
  278.         jsr    (@R_GetColumn)
  279.         move.l    d0,_dc_source(a4) ; dc_source = R_GetColumn(d0,d1)
  280.         movea.l    _colfunc(a4),a0
  281.         jsr    (a0)        ; colfunc ()
  282.         move.l    a2,d0        ; d0 = rw_x
  283. ;;;        lea    _floorclip(a4),a0
  284.         movea.l    _floorclip(a4),a0
  285.         move.w    d6,(a0,d0.l*2)    ; floorclip[rw_x] = mid
  286.         bra.b    19$
  287.  
  288. 16$        tst.l    _markfloor(a4)    ; else if (markfloor)
  289.         beq.b    19$
  290. 18$        addq.l    #1,d3        ; d3 = yh + 1
  291.         move.l    a2,d0        ; d0 = rw_x
  292. ;;;        lea    _floorclip(a4),a0
  293.         movea.l    _floorclip(a4),a0
  294.         move.w    d3,(a0,d0.l*2)    ; floorclip[rw_x] = yh + 1
  295.  
  296. 19$        tst.l    _maskedtexture(a4) ; if (maskedtexture)
  297.         beq.b    11$
  298.         move.l    a2,d0        ; d0 = rw_x
  299.         movea.l    _maskedtexturecol(a4),a0
  300.         move.w    d5,(a0,d0.l*2)    ; maskedtexturecol[rw_x] = texturecolumn
  301.  
  302. 11$        adda.l    _rw_scalestep(a4),a6 ; rw_scale += rw_scalestep
  303.         adda.l    _topstep(a4),a3    ; topfrac += topstep
  304.         adda.l    _bottomstep(a4),a5 ; bottomfrac += bottomstep
  305.         addq.l    #1,a2        ; rw_x++
  306.  
  307. 1$        cmpa.l    _rw_stopx(a4),a2
  308.         blt.w    20$
  309.  
  310.         move.l    a2,_rw_x(a4)
  311.         move.l    a3,_topfrac(a4)
  312.         move.l    a5,_bottomfrac(a4)
  313.         move.l    a6,_rw_scale(a4)
  314.  
  315.         movem.l    (sp)+,d2-d7/a2/a3/a5/a6
  316.         rts
  317.  
  318. ;-----------------------------------------------------------------------
  319. ; R_PointToDist (in r_main.c) by Arto Huusko <arto.huusko@pp.qnet.fi>
  320.  
  321.         xref    _tantoangle    ;FAR angle_t tantoangle[2049]
  322.         xref    _FixedDiv
  323.         xref    _finesine    ;FAR int finesine[10240]
  324.         xref    _viewx
  325.         xref    _viewy
  326.  
  327. DBITS        equ    16-11    ;FRACBITS-SLOPEBITS
  328. ANG90        equ    $40000000
  329. ANGLETOFINESHIFT    equ    19
  330.  
  331. _R_PointToDist:
  332. @R_PointToDist:
  333.         move.l    d2,-(sp)
  334.         move.l    _FixedDiv(a4),a1
  335.  
  336.         move.l    d0,d2
  337.         move.l    d1,d0
  338.  
  339.         sub.l    _viewx(a4),d2
  340.         bpl        .rp_1OK
  341.         neg.l    d2
  342. .rp_1OK:
  343.         sub.l    _viewy(a4),d0
  344.         bpl        .rp_2OK
  345.         neg.l    d0
  346. .rp_2OK:
  347.         cmp.l    d0,d2
  348.         bge        .rp_3OK
  349.         move.l    d0,d1
  350.         move.l    d2,d0
  351.         move.l    d1,d2
  352. .rp_3OK:
  353.         move.l    d2,d1
  354.         jsr    (a1)
  355.         asr.l    #DBITS,d0
  356.         move.l    #_tantoangle,a0
  357.         move.l    (a0,d0.l*4),d1
  358.         add.l    #ANG90,d1
  359.         moveq    #ANGLETOFINESHIFT,d0
  360.         asr.l    d0,d1
  361.         move.l    #_finesine,a0
  362.         move.l    (a0,d1.l*4),d1
  363.         move.l    d2,d0
  364.         jsr    (a1)
  365.  
  366.         move.l    (sp)+,d2
  367.         rts
  368.  
  369. ;fixed_t
  370. ;R_PointToDist
  371. ;( fixed_t    x,
  372. ;  fixed_t    y )
  373. ;{
  374. ;    int        angle;
  375. ;    fixed_t    dx;
  376. ;    fixed_t    dy;
  377. ;    fixed_t    temp;
  378. ;    fixed_t    dist;
  379. ;    
  380. ;    dx = iabs(x - viewx);
  381. ;    dy = iabs(y - viewy);
  382. ;    
  383. ;    if (dy>dx)
  384. ;    {
  385. ;    temp = dx;
  386. ;    dx = dy;
  387. ;    dy = temp;
  388. ;    }
  389. ;    
  390. ;    angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT;
  391. ;
  392. ;    // use as cosine
  393. ;    dist = FixedDiv (dx, finesine[angle] );    
  394. ;    
  395. ;    return dist;
  396. ;}
  397.  
  398. ;-----------------------------------------------------------------------
  399. ; R_RenderMaskedSegRange (in r_segs.c) by Arto Huusko <arto.huusko@pp.qnet.fi>
  400.  
  401.         xref    _curline
  402.         xref    _frontsector
  403.         xref    _backsector
  404.         xref    _extralight
  405.         xref    _walllights        ;lighttable_t**
  406.         xref    _scalelight        ;FAR lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE]
  407.         xref    _maskedtexturecol    ;short*
  408.         xref    _rw_scalestep
  409.         xref    _spryscale
  410.         xref    _mfloorclip
  411.         xref    _mceilingclip
  412.         xref    _dc_texturemid
  413.         xref    _dc_colormap
  414.         xref    _fixedcolormap
  415.         xref    _dc_x
  416.         xref    _sprtopscreen
  417.         xref    _centeryfrac
  418.         xref    _FixedMul
  419.         xref    @R_GetColumn
  420.         xref    @R_DrawMaskedColumn
  421.         xref    _dc_iscale
  422.         xref    _texturetranslation    ;int *
  423.         xref    _textureheight    ;fixed_t*
  424.         xref    _viewz
  425.  
  426. LIGHTSEGSHIFT    equ    4
  427. LIGHTLEVELS    equ    16
  428. LIGHTSCALESHIFT    equ    12
  429. MAXSHORT    equ    $7FFF
  430. MAXLIGHTSCALE    equ    48
  431. ML_DONTPEGBOTTOM equ    16    ;bit number is 4
  432.  
  433.         STRUCTURE    drawseg,0
  434.          APTR    ds_curline
  435.          LONG    ds_x1
  436.          LONG    ds_x2
  437.          LONG    ds_scale1
  438.          LONG    ds_scale2
  439.          LONG    ds_scalestep
  440.          LONG    ds_silhouette
  441.          LONG    ds_bsilheight
  442.          LONG    ds_tsilheight
  443.          APTR    ds_sprtopclip
  444.          APTR    ds_sprbottomclip
  445.          APTR    ds_maskedtexturecol
  446.         LABEL    ds_size
  447.  
  448.         STRUCTURE    seg,0
  449.          APTR    s_v1
  450.          APTR    s_v2
  451.          LONG    s_offset
  452.          LONG    s_angle
  453.          APTR    s_sidedef
  454.          APTR    s_linedef
  455.          APTR    s_frontsect
  456.          APTR    s_backsect
  457.         LABEL    s_size
  458.  
  459.         STRUCTURE    sector,0
  460.          LONG    st_floorheight
  461.          LONG    st_ceilingheight
  462.          WORD    st_floorpic
  463.          WORD    st_ceilingpic
  464.          WORD    st_lightlevel
  465.          WORD    st_special
  466.          WORD    st_tag
  467.          LONG    st_soundtraversed
  468.          APTR    st_soundtarget
  469.          STRUCT    st_blockbox,5
  470.          ;etc. etc.
  471.  
  472.         STRUCTURE    vertex,0
  473.          LONG    v_x
  474.          LONG    v_y
  475.  
  476.         STRUCTURE    line,0
  477.          APTR    l_v1
  478.          APTR    l_v2
  479.          LONG    l_dx
  480.          LONG    l_dy
  481.          WORD    l_flags
  482.          WORD    l_special
  483.          WORD    l_tag
  484.  
  485.         STRUCTURE    side,0
  486.          LONG    sd_textureoffset
  487.          LONG    sd_rowoffset
  488.          WORD    sd_toptexture
  489.          WORD    sd_bottomtexture
  490.          WORD    sd_midtexture
  491.          APTR    sd_sector
  492.  
  493. @R_RenderMaskedSegRange:
  494. _R_RenderMaskedSegRange:
  495.         movem.l    d2-d7/a2/a3/a5,-(sp)
  496.  
  497.         move.l    d0,d5    ;store x1
  498.         move.l    d1,d6    ;and x2
  499.         ;we can keep ds in A0 all the way through
  500.  
  501.         move.l    ds_curline(a0),a1    ;curline.. kept in a1
  502.         move.l    s_frontsect(a1),a2    ;used soon below
  503.         move.l    a1,_curline(a4)
  504.         move.l    a2,_frontsector(a4)
  505.         ;texnum is calculated later...
  506.  
  507. ;BTW the walllights variable is not really used at all in this context
  508. ;for anything else but storage.. so lets just put it to a register.. faster!
  509.         moveq    #0,d2
  510.         move.w    st_lightlevel(a2),d2
  511.         lsr.w    #LIGHTSEGSHIFT,d2
  512.         move.l    s_backsect(a1),_backsector(a4)
  513.         add.l    _extralight(a4),d2
  514.  
  515.         move.l    #_scalelight,a5    ;walllights=scalelight[0]
  516.  
  517.         move.l    s_v1(a1),a3    ;pick coords from vertex one.. compare from vertex two
  518.         move.l    v_y(a3),d0
  519.         move.l    v_x(a3),d1
  520.         move.l    s_v2(a1),a3
  521.         cmp.l    v_y(a3),d0
  522.         bne.b    .rr_Skip1
  523.         subq.l    #1,d2
  524.         bra.b    .rr_LN1Go
  525. .rr_Skip1:
  526.         cmp.l    v_x(a3),d1
  527.         bne.b    .rr_LN1Go
  528.         addq.l    #1,d2
  529. .rr_LN1Go:
  530.         tst.l    d2
  531.         bmi.b    .rr_LightsOK    ;negative.. keep walllights as it is
  532.         cmp.l    #16,d2
  533.         bmi.b    .rr_LightnumOK
  534.         add.l    #2880,a5
  535.         bra.b    .rr_LightsOK
  536. .rr_LightnumOK:
  537.         move.l    d2,d1
  538.         lsl.l    #7,d2
  539.         lsl.l    #6,d1
  540.         add.l    d1,a5
  541.         add.l    d2,a5    ;scalelight[lightnum]
  542. .rr_LightsOK:
  543.         move.l    ds_maskedtexturecol(a0),_maskedtexturecol(a4)
  544.  
  545.         move.l    ds_scalestep(a0),d1
  546.         move.l    d1,_rw_scalestep(a4)
  547.         move.l    ds_sprbottomclip(a0),_mfloorclip(a4)
  548.         move.l    ds_sprtopclip(a0),_mceilingclip(a4)
  549.         move.l    d5,d0
  550.         sub.l    ds_x1(a0),d0
  551.         muls.l    d1,d0
  552.         add.l    ds_scale1(a0),d0
  553.         move.l    d0,_spryscale(a4)
  554.  
  555.         move.l    s_sidedef(a1),a0
  556.         move.l    sd_rowoffset(a0),_dc_texturemid(a4)    ;dc_texturemid += curline->sidedef->rowoffset
  557.         move.w    sd_midtexture(a0),d0
  558.         move.l    _texturetranslation(a4),a0
  559.         move.l    (a0,d0.w*4),d7    ;texnum
  560.  
  561.         move.l    s_linedef(a1),a0
  562.         move.w    l_flags(a0),d0
  563.  
  564.         move.l    _frontsector(a4),a0
  565.         move.l    _backsector(a4),a2
  566.  
  567.         btst.l    #4,d0    ;test for ML_DONTPEGBOTTOM
  568.         beq.b    .rr_tmid2
  569.         move.l    st_floorheight(a0),d0
  570.         cmp.l    st_floorheight(a2),d0
  571.         bgt.b    .rrtm1_OK
  572.         move.l    st_floorheight(a2),d0
  573. .rrtm1_OK:
  574.         sub.l    _viewz(a4),d0
  575.         move.l    _textureheight(a4),a0
  576.         add.l    (a0,d7.l*4),d0
  577.         add.l    d0,_dc_texturemid(a4)
  578.         bra.b    .rr_tmidDone
  579. .rr_tmid2:
  580.         move.l    st_ceilingheight(a0),d0
  581.         cmp.l    st_ceilingheight(a2),d0
  582.         blt.b    .rrtm2_OK
  583.         move.l    st_ceilingheight(a2),d0
  584. .rrtm2_OK:
  585.         sub.l    _viewz(a4),d0
  586.         add.l    d0,_dc_texturemid(a4)
  587. .rr_tmidDone:
  588.  
  589.         move.l    _fixedcolormap(a4),d0
  590.         beq.b    .rr_NoFixCMAP
  591.         move.l    d0,_dc_colormap(a4)
  592. .rr_NoFixCMAP:
  593.  
  594. ;prepare everything for the loop
  595.         move.l    d5,_dc_x(a4)
  596.         sub.l    d5,d6
  597.         blt.b    .rr_SkipLoop
  598.         move.l    _maskedtexturecol(a4),a3
  599.         add.l    d5,a3
  600.         add.l    d5,a3    ;&maskedtexturecol[dc_x]
  601.         moveq    #12,d5
  602.         move.l    _FixedMul(a4),a2
  603.         move.l    _spryscale(a4),d2
  604.         move.l    _dc_texturemid(a4),d3
  605.         move.l    _rw_scalestep(a4),d4
  606. .rr_Loop:
  607.         cmp.w    #MAXSHORT,(a3)
  608.         beq.b    .rrl_SkipAll
  609.         tst.l    _fixedcolormap(a4)
  610.         bne.b    .rrl_SkipCMAP
  611.         move.l    d2,d0
  612.         lsr.l    d5,d0
  613.         cmp.l    #MAXLIGHTSCALE,d0
  614.         bmi.b    .rrl_IndexOK
  615.         moveq    #48,d0    ;saves us a branch
  616. .rrl_IndexOK:
  617.         move.l    (a5,d0.l*4),_dc_colormap(a4)
  618.  
  619. .rrl_SkipCMAP:
  620.         moveq    #-1,d0
  621.         divu.l    d2,d0
  622.         move.l    _centeryfrac(a4),_sprtopscreen(a4)    ;scheduling, helps a bit
  623.         move.l    d0,_dc_iscale(a4)
  624.         move.l    d3,d0
  625.         move.l    d2,d1
  626.         jsr    (a2)
  627.         sub.l    d0,_sprtopscreen(a4)
  628.  
  629.         move.l    d7,d0
  630.         moveq    #0,d1
  631.         move.w    (a3),d1
  632.         jsr    (@R_GetColumn)
  633.         subq.l    #3,d0
  634.         move.l    d0,a0
  635.         jsr    (@R_DrawMaskedColumn)
  636.         move.w    #MAXSHORT,(a3)
  637.  
  638. .rrl_SkipAll:
  639.         addq.l    #2,a3
  640.         addq.l    #1,_dc_x(a4)
  641.         add.l    d4,d2
  642.         move.l    d2,_spryscale(a4)
  643.         dbf    d6,.rr_Loop
  644. .rr_SkipLoop:
  645.         movem.l    (sp)+,d2-d7/a2/a3/a5
  646.  
  647.         rts
  648.  
  649.  
  650. ;void
  651. ;R_RenderMaskedSegRange
  652. ;( drawseg_t*    ds,
  653. ;  int        x1,
  654. ;  int        x2 )
  655. ;{
  656. ;    unsigned    index;
  657. ;    column_t*    col;
  658. ;    int        lightnum;
  659. ;    int        texnum;
  660. ;    
  661. ;    curline = ds->curline;
  662. ;    frontsector = curline->frontsector;
  663. ;    backsector = curline->backsector;
  664. ;    texnum = texturetranslation[curline->sidedef->midtexture];
  665. ;    
  666. ;    lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT)+extralight;
  667. ;
  668. ;    if (curline->v1->y == curline->v2->y)
  669. ;    lightnum--;
  670. ;    else if (curline->v1->x == curline->v2->x)
  671. ;    lightnum++;
  672. ;
  673. ;    if (lightnum < 0)
  674. ;    walllights = scalelight[0];
  675. ;    else if (lightnum >= LIGHTLEVELS)
  676. ;    walllights = scalelight[LIGHTLEVELS-1];
  677. ;    else
  678. ;    walllights = scalelight[lightnum];
  679. ;
  680. ;    maskedtexturecol = ds->maskedtexturecol;
  681. ;
  682. ;    rw_scalestep = ds->scalestep;        
  683. ;    spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep;
  684. ;    mfloorclip = ds->sprbottomclip;
  685. ;    mceilingclip = ds->sprtopclip;
  686. ;
  687. ;    if (curline->linedef->flags & ML_DONTPEGBOTTOM)
  688. ;    {
  689. ;    dc_texturemid = frontsector->floorheight > backsector->floorheight
  690. ;        ? frontsector->floorheight : backsector->floorheight;
  691. ;    dc_texturemid = dc_texturemid + textureheight[texnum] - viewz;
  692. ;    }
  693. ;    else
  694. ;    {
  695. ;    dc_texturemid =frontsector->ceilingheight<backsector->ceilingheight
  696. ;        ? frontsector->ceilingheight : backsector->ceilingheight;
  697. ;    dc_texturemid = dc_texturemid - viewz;
  698. ;    }
  699. ;    dc_texturemid += curline->sidedef->rowoffset;
  700. ;            
  701. ;    if (fixedcolormap)
  702. ;    dc_colormap = fixedcolormap;
  703. ;    
  704. ;    for (dc_x = x1 ; dc_x <= x2 ; dc_x++)
  705. ;    {
  706. ;    if (maskedtexturecol[dc_x] != MAXSHORT)
  707. ;    {
  708. ;        if (!fixedcolormap)
  709. ;        {
  710. ;        index = spryscale>>LIGHTSCALESHIFT;
  711. ;
  712. ;        if (index >=  MAXLIGHTSCALE )
  713. ;            index = MAXLIGHTSCALE-1;
  714. ;
  715. ;        dc_colormap = walllights[index];
  716. ;        }
  717. ;            
  718. ;        sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale);
  719. ;        dc_iscale = 0xffffffffu / (unsigned)spryscale;
  720. ;        
  721. ;        col = (column_t *)( 
  722. ;        (byte *)R_GetColumn(texnum,maskedtexturecol[dc_x]) -3);
  723. ;            
  724. ;        R_DrawMaskedColumn (col);
  725. ;        maskedtexturecol[dc_x] = MAXSHORT;
  726. ;    }
  727. ;    spryscale += rw_scalestep;
  728. ;    }
  729. ;    
  730. ;}
  731.  
  732. ;-----------------------------------------------------------------------
  733. ; R_ScaleFromGlobalAngle (in r_main.c) by Arto Huusko <arto.huusko@pp.qnet.fi>
  734.  
  735.         xref    _viewangle
  736.         xref    _rw_normalangle
  737.         xref    _finesine
  738.         xref    _projection
  739.         xref    _rw_distance
  740.         xref    _FixedMul
  741.         xref    _FixedDiv
  742.         xref    _detailshift
  743.  
  744. ;ANGLETOFINESHIFT    EQU    19
  745. ;ANG90        EQU    $40000000
  746.  
  747. _R_ScaleFromGlobalAngle:
  748. @R_ScaleFromGlobalAngle:
  749.         move.l    d2,-(sp)
  750.         add.l    #ANG90,d0
  751.         move.l    d0,d1
  752.         sub.l    _viewangle(a4),d0
  753.         sub.l    _rw_normalangle(a4),d1
  754.  
  755.         moveq    #ANGLETOFINESHIFT,d2
  756.         lsr.l    d2,d1
  757.         lsr.l    d2,d0
  758.         move.l    #_finesine,a0
  759.         move.l    (a0,d1.l*4),d2    ;sineb
  760.         move.l    (a0,d0.l*4),d1    ;sinea
  761.         move.l    _rw_distance(a4),d0
  762.         move.l    _FixedMul(a4),a1
  763.         jsr    (a1)
  764.         move.l    d2,d1
  765.         move.l    d0,d2
  766.         move.l    _projection(a4),d0
  767.         jsr    (a1)
  768.         move.l    _detailshift(a4),d1
  769.         lsl.l    d1,d0
  770.  
  771.         move.l    d0,d1
  772.         swap    d1
  773.         and.l    #$FFFF,d1
  774.         cmp.l    d2,d1
  775.         bpl.b    .rs_Return1
  776.  
  777.         move.l    d2,d1
  778.         move.l    _FixedDiv(a4),a0
  779.         jsr    (a0)
  780.         cmp.l    #64*(1<<16),d0
  781.         bpl.b    .rs_Return1
  782.         cmp.l    #256,d0
  783.         bpl.b    .rs_Exit
  784.         move.l    #256,d0
  785.         move.l    (sp)+,d2
  786.         rts
  787.  
  788. .rs_Return1:
  789.         move.l    #64*(1<<16),d0
  790. .rs_Exit:
  791.         move.l    (sp)+,d2
  792.         rts
  793.  
  794. ;-----------------------------------------------------------------------
  795.  
  796.         end
  797.